//
//  XYViewController.m
//  Calculator
//
//  Created by Xia Yong on 12-12-5.
//  Copyright (c) 2012年 Xia Yong. All rights reserved.
//

#import "XYViewController.h"

@interface XYViewController ()

@end

@implementation XYViewController

@synthesize calculatorData = _calculatorData;

- (XYCalculatorModel *) calculatorData {
    if(!_calculatorData) {
        _calculatorData = [[XYCalculatorModel alloc] init];
    }
    return _calculatorData;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)typeTheNumber:(UIButton *)sender {
    NSString *number = sender.currentTitle;
    NSLog(@"the customer type the number %@", number);
    self.screen.text = [self.screen.text stringByAppendingString:number];
}

- (IBAction)typeTheSign:(UIButton *)sender {
    NSNumber *number = [NSNumber numberWithDouble:[self.screen.text doubleValue]];
    NSLog(@"pust the %@ to the data stack", number);
    [self.calculatorData addNumber:number];
    
    NSString *sign = sender.currentTitle;
    NSLog(@"the customer type the %@, push the starting + calculate", sign);
    double result = [self.calculatorData calculate:sign];
    NSLog(@"displaying the result: %g", result);
    self.screen.text = [NSString stringWithFormat:@"%g", result];
}

- (IBAction)typeTheEnter:(UIButton *)sender {
    NSNumber *number = [NSNumber numberWithDouble:[self.screen.text doubleValue]];
    NSLog(@"the customer type the enter key, push the %@ to data stack",number);
    [self.calculatorData addNumber:number];
    self.screen.text = @"0";
}
@end
